<template>
	<view class="page">
		<image class="returnBack" src="../../../static/img/return-white.png" mode="widthFix" :style="{top:navTop+'px'}" @click="back"></image>
		<view class="top-wrap" :style="{paddingTop:navHeight + 'px',height:`calc(${navHeight}px + 220rpx)`}">
			<image class="banner" src="../../../static/mine/mineBanner.png"></image>
			<view class="top-content">
				<view class="user-wrap">
					<view class="user-msg">
						<view class="tx">
							<!-- <image class="tx-pic" :src="fileServer+memberInfo.headImg"></image> -->
							<u-avatar class="tx-pic" mode="aspectFill" size="108rpx" :src="userInfo.headImg?fileServer+userInfo.headImg:null"></u-avatar>
							<image v-if="memberInfo.sfVip==1" class="vip" src="../../../static/img/vip-icon.png" mode="widthFix"></image>
						</view>
						<view class="msg">
							<view class="name">
								{{memberInfo.name||'--'}}
							</view>
							<view class="phone">
								{{memberInfo.mobile||'--'}}
							</view>
						</view>
					</view>
					<view class="jf">
						<view class="label">
							我的积分
						</view>
						<view class="value">
							{{memberInfo.jifen||0}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="main">
			<view class="card">
				<view class="title">
					<view class="l">
						<view class="l-t">
							我的
						</view>
						<view class="l-p">
							邀请人数：{{memberInfo.yqrNum||0}}
						</view>
					</view>
					<view class="r" @click="goRecord">
						积分详情 >
					</view>
				</view>
			</view>
			<view class="page-label">
				<text>做任务赚积分</text>
			</view>
			<view class="lists">
				<view class="list" v-for="(item,index) in taskList" :key="index">
					<view class="list-l">
						<image class="icon" :src="item.img||'../../../static/mineJF/icon1.png'"></image>
						<view class="msg">
							<view class="label">
								{{item.title}}
							</view>
							<view class="desc">
								{{item.miaoshu}}
							</view>
						</view>
					</view>
					<view class="btn ok" v-if="item.sfwc==1">
						<!-- {{item.btnTextOk}} -->已完成
					</view>
					<view @click="taskBtn(item.taskCode)" class="btn no" v-else-if="item.taskCode=='Task-NewUserLogin'">
						去登录
					</view>
					<view @click="taskBtn(item.taskCode)" class="btn no" v-else-if="item.taskCode=='Task-RegisterMingPian'">
						去注册
					</view>
					<!-- <view @click="taskBtn(item.taskCode)" class="btn no" v-else-if="item.taskCode=='Task_ZhanFaInvite'">
						去邀请
					</view> -->
					<button open-type="share" v-else-if="item.taskCode=='Task_ZhanFaInvite'" class="btn no">
						去邀请
					</button>
				</view>
			</view>
			<view class="page-label">
				<text>积分兑换</text>
				<view class="kg">
					积分联系客户提示开关
					<view style="margin-right: 10rpx;"></view>
					<!-- memberInfo.sfLxkhkjf -->
					<u-switch size="18" activeValue="1" inactiveValue='0' @change="switchChange" v-model="memberInfo.sfLxkhkjf" inactiveColor="rgba(223, 223, 223, 1)"></u-switch>
				</view>
			</view>
			<view class="lists">
				<view class="list" v-for="(item,index) in dhList" :key="'btn2List'+index">
					<view class="list-l">
						<image class="icon" :src="item.img||'../../../static/mineJF/icon1.png'"></image>
						<view class="msg">
							<view class="label">
								{{item.title}}
							</view>
							<view class="desc">
								{{item.miaoshu}}
							</view>
						</view>
					</view>
					<!-- <view class="btn ok" v-if="item.okStatus">
						{{item.btnTextOk}}
					</view> -->
					<view class="btn no" @click="dhBtn(index)">
						{{item.btnText}}
					</view>
				</view>
			</view>
			<!-- <view class="page-label">
				<text>积分兑换</text>
			</view>
			<view class="lists">
				<view class="list" v-for="(item,index) in btn3List" :key="'btn3List'+index">
					<view class="list-l">
						<image class="icon" :src="item.image"></image>
						<view class="msg">
							<view class="label">
								{{item.title}}
							</view>
							<view class="desc">
								{{item.desc}}
							</view>
						</view>
					</view>
					<view class="btn ok" v-if="item.okStatus">
						{{item.btnTextOk}}
					</view>
					<view class="btn no" v-else @click="toBuy">
						{{item.btnText}}
					</view>
				</view>
			</view>
		 -->
		</view>
		<view class="page-btm-tc">

		</view>
		<view class="page-btm">
			<view class="myzs">
				我的专属客服 >
			</view>
			<view class="myxy">
				本平台信息不代表官方平台观点，投资有风险
				<text style="color: #AD2323;margin-left: 16rpx;">用户使用协议</text>
			</view>
		</view>
		<u-popup :show="show" mode="bottom" round="24rpx">
			<view class="pop-wrap">
				<view class="pop-title">
					积分充值
					<view  style="float: right;">
						<u-icon name="close" color="#333333" size="22" bold @click="show = false"></u-icon>
					</view>
				</view>
				<view class="check-wrap">
					<view class="check-list" @click="changeJf(index)" :class="index==jfIndex?'active':''" v-for="(item,index) in jfList" :key="index">
						<view class="check">
							<view class="check-title">
								<image class="money" src="../../../static/mineJF/money.png" mode="widthFix"></image>
								{{item.jifenNum}}积分
							</view>
							<view class="check-money">
								¥{{item.money}}
							</view>
						</view>
						<image class="red-check" src="../../../static/mineJF/check-red.png" mode="widthFix"></image>
					</view>
				</view>
				<view class="wx-pay">
					<view class="wx-title">
						<image class="wx" src="../../../static/mineJF/wx-pay.png" mode="widthFix"></image>
						微信支付
					</view>
					<image class="green-check" src="../../../static/mineJF/check-green.png" mode="widthFix"></image>
				</view>
				<view class="pay-btn" @click="createOrderBtn">
					确定充值
				</view>
			</view>
		</u-popup>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				fileServer: this.$fileServer,
				navHeight: 0,
				navTop:0,
				btn3List: [{
					image: '../../../static/mineJF/icon9.png',
					title: '购买积分',
					desc: '10元即可购买10积分',
					path: '',
					btnText: '去购买',
					btnTextOk: '去购买',
					okStatus: false,
				}],
				show: false,
				memberInfo:{},
				taskList:[],
				dhList:[],
				jfList:[],
				jfIndex:0,
			}
		},
		onLoad() {

			// #ifdef MP-WEIXIN
			let statusBarHeight = uni.getSystemInfoSync().statusBarHeight
			const custom = wx.getMenuButtonBoundingClientRect()

			let navigationBarHeight = custom.height + (custom.top - statusBarHeight) * 2
			this.navTop = custom.top + 6
			this.navHeight = navigationBarHeight + statusBarHeight

			// #endif
			
		},
		onShow(){
			this.getInfo();
		},
		methods: {
			// 去积分记录页面
			goRecord(){
				uni.navigateTo({
					url:'/pages/mine/integralRecord/integralRecord'
				})
			},
			getInfo(){ 
				this.$api.member.getJifenIndex().then(res => {
					console.log(res)
					if(res.flag){
						let info = res.data;
						this.dhList = info.dhList
						this.memberInfo = info.member
						this.taskList = info.taskList
					}
				})
			},
			// 任务--按钮
			taskBtn(code){
				console.log(code)
				if(code=='Task-RegisterMingPian'){//去注册名片
					uni.navigateTo({
						url:'/pages/card/cardEdit/cardEdit'
					})
				}else if(code=='Task_ZhanFaInvite'){//去邀请
					uni.navigateTo({
						url:'/pages/card/cardEdit/cardEdit'
					})
				}
			},
			// 兑换按钮
			dhBtn(index){
				let item = this.dhList[index];
				// console.log(item);
				if(item.dhCode == "lianxiKehuCode"){//直接联系客户
					uni.switchTab({
						url:'/pages/tabBar/client/client'
					})
				}else if(item.dhCode == "productTopCode"||item.dhCode == "guanggaoShowCode"||item.dhCode == "jifenToZhuSuCode"||item.dhCode == "jifenToVipCode"||item.dhCode == "jifenToMoneyCode"){
					//住宿兑换 、会员兑换、换现金、广告展示、产品置顶
					this.useJifenFun(item.dhCode);
				}else if(item.dhCode == "buyJifenCode"){//购买积分
					this.JifenList(item.id);
				}else if(item.dhCode == "zhuanfaProductCode"){//转发产品
					uni.navigateTo({
						url:'/pages/client/transmit/transmit'
					})
				}else if(item.dhCode == "mingpianZhiDing"){//去置顶
					uni.navigateTo({
						url:'/pages/client/rankUp/rankUp'
					})
				}
				
				
			},
			// 兑换
			useJifenFun(dhCode){
				let refId = uni.getStorageSync("memberId");
				this.$api.member.useJifen({dhCode,refId}).then(res => {
					// console.log(res)
					if(res.flag){
						uni.showToast({
							title:res.msg,
							icon:'none'
						})
						this.getInfo();
					}
				})
			},
			// 积分列表
			JifenList(id){
				this.$api.member.getBuyJifenList({gmjfId:id}).then(res => {
					// console.log(res)
					if(res.flag){
						let jfList = res.data;
						this.jfList = jfList;
						this.show = true
					}
				})
			},
			// 选择积分
			changeJf(index){
				this.jfIndex = index;
			},
			// 积分--确认下单
			createOrderBtn(){
				let gmjfId = this.jfList[this.jfIndex].id;
				this.$api.member.createOrder({gmjfId:gmjfId}).then(res => {
					console.log(res)
					if(res.flag){
						let obj = res.data;
						uni.requestPayment({
							provider: 'wxpay',
							timeStamp: obj.timestamp,
							nonceStr: obj.noncestr,
							package: obj.paypackage,
							signType: obj.signType,
							paySign: obj.paySign,
							success: res=>{
								this.show = false
								this.getInfo();
							},
							fail: function (err) {
								console.log('fail:' + JSON.stringify(err));
							}
						});
						

					}
				})
			},
			// 积分联系客户提示开关
			switchChange(value){
				console.log(value)
				 let status = 0;
				if(value){
					status = 1;
				}
				this.$api.member.closeOrOpenLxkh({status}).then(res => {
					console.log(res)
					if(res.flag){
						
					}
				})
			},
			back(){
				uni.navigateBack()
			},
			clickServe(item) {
				console.log('ttt', item);
			},
			// toBuy() {
			// 	this.show = true
			// },
		},
		// #ifdef MP-WEIXIN
		onShareAppMessage(res) {
		    if (res.from === 'button') {// 来自页面内分享按钮
		        console.log('999')
		    }
			let yqrId = uni.getStorageSync("memberId")||'';
		    return {
		        title: '快消家', //分享的名称
		        path: `/pages/tabBar/mine/mine?yqrId=${yqrId}`,
		        
		    }
		},
		// #endif

	}
</script>

<style lang="scss" scoped>
	.page {
		background: #F8F9FA;

		.main {
			width: 100%;
			padding: 0 30rpx;
			position: relative;
			top: -80rpx;
			z-index: 3;

			.ad1 {
				width: 100%;
				height: auto;
			}

			.ad-list {
				width: 100%;
				height: auto;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.ad {
					flex: 1;
					height: auto;
				}

			}


		}
	}
	.returnBack{
		position: absolute;
		left: 32rpx;
		width: 32rpx;
		height: auto;
		z-index: 999;
	}
	.top-wrap {
		width: 100%;
		height: auto;
		position: relative;

		.banner {
			width: 100%;
			height: 100%;
			position: absolute;
			z-index: 1;
			top: 0;
			left: 0;
		}

		.top-content {
			width: 100%;
			height: 100%;
			position: relative;
			z-index: 2;
			overflow: hidden;

			.user-wrap {
				margin-top: 16rpx;
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0 30rpx;

				.user-msg {
					width: 100%;
					display: flex;
					align-items: center;

					.tx {
						width: 112rpx;
						border-radius: 50%;
						border: 2rpx solid #ffffff;
						height: 112rpx;
						position: relative;

						.tx-pic {
							width: 100%;
							height: 100%;
							border-radius: 50%;
							display: block;
						}

						.vip {
							position: absolute;
							right: 0;
							top: 6rpx;
							width: 28rpx;
							height: auto;

						}
					}

					.msg {
						margin-left: 30rpx;

						.name {
							font-size: 32rpx;
							font-weight: bold;
							color: #FFFFFF;
							line-height: 44rpx;
							margin-bottom: 4rpx;
						}

						.phone {
							font-size: 24rpx;
							color: #FFFFFF;
							opacity: 0.8;
						}
					}
				}

				.jf {
					display: flex;
					align-items: center;
					flex-shrink: 0;

					.label {
						font-size: 24rpx;
						color: #FFFFFF;
						opacity: 0.8;
						flex-shrink: 0;
					}

					.value {
						font-size: 36rpx;
						font-weight: bold;
						color: #FFFFFF;
						flex-shrink: 0;
						margin-left: 20rpx;
					}
				}
			}
		}
	}

	.card {
		background: #FFFFFF;
		border-radius: 20rpx;

		.title {
			padding: 36rpx 40rpx 36rpx 36rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.l {
				display: flex;
				align-items: center;

				.l-t {

					font-size: 28rpx;
					font-weight: bold;
					margin-right: 14rpx;
				}

				.l-p {
					color: #777777;
					font-size: 28rpx;
				}
			}

			.r {
				font-size: 28rpx;
			}
		}

		.my-serve {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			margin-bottom: 20rpx;
			position: relative;

			.pic {
				width: 76rpx;
				height: 76rpx;
				margin-bottom: 8rpx;
			}

			.grid-text {
				font-size: 28rpx;
			}
		}

		.title1 {
			padding: 24rpx 24rpx 12rpx;

			font-size: 28rpx;
			font-weight: bold;
		}

		.content {
			font-size: 24rpx;
			color: #777777;
			line-height: 34rpx;
			padding: 0 24rpx;
		}

		.btn-wrap {
			margin-top: 34rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			padding-bottom: 32rpx;

			.btn {
				width: 244rpx;
				height: 70rpx;
				border-radius: 35rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 26rpx;
				font-weight: bold;
				margin: 0 30rpx;

				&.btn1 {
					color: #EC2424;
					border: 1px solid #EC2424;
				}

				&.btn2 {
					color: #FFFFFF;
					background: #EC2424;
				}
			}
		}
	}

	.page-label {
		width: 100%;
		margin: 24rpx 0 10rpx 0;
		padding-left: 14rpx;
		position: relative;
		height: 40rpx;
		line-height: 40rpx;
		font-size: 28rpx;
		font-weight: bold;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.kg {
			display: flex;
			align-items: center;
			color: #777777;
			font-size: 24rpx;
		}

		&::after {
			content: '';
			position: absolute;
			left: 0;
			top: 50%;
			transform: translateY(-50%);
			width: 4rpx;
			height: 30rpx;
			background: #E54848;
			border-radius: 1px;
		}
	}

	.page-btm-tc {
		height: 116rpx;
		width: 100%;
	}

	.page-btm {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		z-index: 4;
		background-color: #fff;

		.myzs {
			width: 100%;
			height: 54rpx;
			background: rgba(236, 36, 36, 0.09);
			line-height: 54rpx;
			text-align: center;
			color: #EC2424;
			font-size: 22rpx;
		}

		.myxy {
			width: 100%;
			height: 54rpx;
			background: rgba(236, 174, 36, 0.09);
			text-align: center;
			line-height: 54rpx;
			font-size: 22rpx;
			color: #AAAAAA;
		}
	}

	.lists {
		background: #FFFFFF;
		border-radius: 20rpx;
		width: 100%;
		padding: 0 24rpx;

		.list {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 24rpx 0 20rpx 0;
			border-bottom: 1px solid #F1F1F1;

			&:last-child {
				border-bottom: 1px solid transparent;
			}

			.list-l {
				display: flex;
				align-items: center;

				.icon {
					width: 76rpx;
					height: 76rpx;
					margin-right: 20rpx;
				}

				.msg {
					.label {
						font-size: 28rpx;
						font-weight: bold;
					}

					.desc {
						font-size: 24rpx;
						color: #777777;
					}
				}
			}

			.btn {
				width: 144rpx;
				height: 60rpx;
				border-radius: 35rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 28rpx;
				color: #FFFFFF;
				font-weight: bold;
				margin: 0;
				&.ok {
					background: #BCBCBC;
				}

				&.no {
					background: #EC2424;
				}
			}
		}
	}

	.pop-wrap {
		width: 100%;
		padding: 32rpx 60rpx;

		.pop-title {
			text-align: center;
			font-size: 32rpx;
			font-weight: bold;
			margin-bottom: 58rpx;
			overflow: hidden;
		}

		.check-wrap {
			overflow: hidden;
			width: 100%;

			.check-list {
				float: left;
				width: 296rpx;
				height: 130rpx;
				margin-right: 38rpx;
				margin-bottom: 24rpx;
				background: #F1EFF0;
				border-radius: 16px;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0 36rpx 0 12rpx;

				.red-check {
					width: 40rpx;
					height: 40rpx;
				}

				&:nth-child(2n+0) {
					margin-right: 0;
				}

				.check-title {
					display: flex;
					align-items: center;
					font-size: 32rpx;
					font-weight: bold;
					line-height: 44rpx;

					.money {
						width: 30rpx;
						height: 30rpx;

					}
				}

				.check-money {
					line-height: 44rpx;
					font-size: 32rpx;
					color: #777777;
					padding-left: 32rpx;
				}

				&.active {
					background: #FFDDDD;
					border: 1px solid #EC2424;

					.check-title {
						color: #EC2424;
					}

					.check-money {
						color: #EC2424;
					}

				}
			}
		}

		.wx-pay {
			margin-top: 18rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.wx-title {
				display: flex;
				align-items: center;

				.wx {
					width: 50rpx;
					height: 50rpx;
					margin-right: 20rpx;


				}
			}

			.green-check {
				width: 40rpx;
				height: 40rpx;

			}
		}

		.pay-btn {
			width: 244rpx;
			height: 70rpx;
			background: #EC2424;
			border-radius: 42rpx;
			margin: 66rpx auto 0;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 26rpx;
			color: #FFFFFF;
			font-weight: bold;
		}
	}
</style>